package com.woniuxy.secondhand.controller;


import com.woniuxy.life.core.api.CommonResult;
import com.woniuxy.secondhand.entity.SecComment;
import com.woniuxy.secondhand.service.SecCommentService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 二手产品留言 前端控制器
 * </p>
 *
 * @author chaohuijiang
 * @since 2020-09-24
 */
@RestController
@RequestMapping("/secondhand/sec-comment")
public class SecCommentController {
@Resource
    SecCommentService secCommentService;
   //添加留言信息
    @RequestMapping("/insert")
    public CommonResult<SecComment> insert(@RequestBody SecComment secComment){
        //存入数据库相关表
        secCommentService.save(secComment);
        return CommonResult.success();
    }
    //删除留言
    @RequestMapping("/delete/{secCommentId}")
    public CommonResult<SecComment> delete(@PathVariable("secCommentId") Integer secCommentId ){
       boolean re= secCommentService.removeById(secCommentId);
       if (re){
           return CommonResult.success();
       }return CommonResult.failed();
    }
    //查询所有留言
    @RequestMapping("/findall")
    public CommonResult<List<SecComment>> finaAll(){
        List<SecComment> secComments= secCommentService.list();
        return CommonResult.success(secComments);
    }
}
